﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace DGIS.Map.Converts
{
    public class SpeedConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString()))
                value = "0";

            double speed = double.Parse(value.ToString());

            string result = "";
            if (speed <= 0)
            {

            }else if (speed < 1024)
            {
                result = string.Format("{0}KB/S",speed);
            }
            else
            {
                result = string.Format("{0}MB/S",Math.Round(speed/=1024,2));
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
